<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        input {
            width: 200px;
            height: 100px;
            border: 1px solid pink;
            /* outline: none; */
            /* resize: none; */
        }
        ul {
            margin-top: 50px;
        }

        li {
            width: 300px;
            padding: 5px;
            background-color: pink;
            color: red;
            font-size: 14px;
            margin: 15px 0;
        }
        li a {
            float: right;
        }
    </style>
</head>

<body>
    <input type="text">
    <button>发布</button>
    <button>删除</button>
    <ul>

    </ul>   
    <script>
        var button = document.querySelector('button');
        var ul = document.querySelector('ul');
        var input = document.querySelector('input');
        button.onclick = function () {
            if (input.value == '') {
                alert('您没有输入内容');
                return false;
            }
            else {
                var li = document.createElement('li');
                li.innerHTML = input.value+"<a href='javascript:;'>删除</a>";
                ul.insertBefore(li,ul.children[0]);
                var as =document.querySelectorAll('a');
                for(var i =0;i<as.length;i++){
                    as[i].onclick=function(){
                        ul.removeChild(this.parentNode);
                    }
                }
                input.value = '';
            }
        }
    </script>
</body>

</html>